import JSBridge from './JSBridge'
const jsBridge = JSBridge.getInstance()

/**
 * js与原生页面的跳转 衔接管理类
 *
 */

export const pushToTestPage = () => {
  const iOSParams = {
    'class': 'LayoutViewController',
    'property': {}
  }

  // let jsBridge = new JSBridge()
  jsBridge.nativePush(iOSParams, {}, (res) => {
    console.log('object')
  })
}

/**
 * 跳转到原生购物车界面
 */
export const pushToShopCartPage = () => {
  const iOSParams = {
    'class': 'ShopCarViewController',
    'property': {}
  }

  const AndroidParams = {
    'classname': 'ShopCarActivity',
    'property': {}
  }
  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到购物车界面')
  })
}

/**
 * 跳转到商品详情页面
 * @param {*} id 商品id
 */
export const pushToGoodsDetailPage = (id) => {
  const iOSParams = {
    'class': 'GoodsDetailViewController',
    'property': {
      'goods_id': id
    }
  }

  const AndroidParams = {
    'classname': 'GoodsDetailActivity',
    'property': {
      'id': String(id)
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到商品详情页面')
  })
}

/**
 * 跳转到商品二级分类页面
 * @param {*} id 分类id
 */
export const pushToCategorySecondPage = (id) => {
  const iOSParams = {
    'class': 'CategorySecondViewController',
    'property': {
      'cate_id': id
    }
  }

  const AndroidParams = {
    'classname': 'CategorySecondActivity',
    'property': {
      'id': String(id)
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到商品二级分类界面')
  })
}

/**
 * 跳转到文章栏目分类页面
 * @param {*} id 栏目ID
 */
export const pushToArticleChannelPage = (id) => {
  const iOSParams = {
    'class': 'ArticleChannelViewController',
    'property': {
      'cate_id': id
    }
  }

  const AndroidParams = {
    'classname': 'ArticleChannelActivity',
    'property': {
      'id': String(id)
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到文章栏目分类界面')
  })
}

/**
 * 跳转到文章详情页面
 * @param {*} type 文章类型
 * @param {*} id 文章ID
 */
export const pushToArticlePage = (type, id) => {
  const iOSParams = {
    'class': 'ArticleViewController',
    'property': {
      'type': type,
      'article_id': id
    }
  }

  const AndroidParams = {
    'classname': 'ArticleActivity',
    'property': {
      'type': String(type),
      'id': String(id)
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到文章详情界面')
  })
}

/**
 * 跳转到普通H5页面
 * @param {*} url 链接地址
 */
export const pushToDefaultPage = (url) => {
  const iOSParams = {
    'class': 'NormalWebViewController',
    'property': {
      'url': url
    }
  }

  const AndroidParams = {
    'classname': 'NormalWebActivity',
    'property': {
      'url': url
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到普通H5界面')
  })
}

/**
 * 跳转到自定义控制页面
 * @param {*} url 链接地址
 */
export const pushToMagicPage = (url) => {
  const iOSParams = {
    'class': 'MagicViewController',
    'property': {
      'url': url
    }
  }

  const AndroidParams = {
    'classname': 'MagicActivity',
    'property': {
      'url': url
    }
  }

  console.log(iOSParams)
  jsBridge.nativePush(iOSParams, AndroidParams, (res) => {
    console.log('跳转到自定义控制页面')
  })
}
